home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 10.9 KB | 345 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: MovieSel.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef MOVIESEL_H
- #include "MovieSel.h"
- #endif
-
- #ifndef MOVIEPAR_H
- #include "MoviePar.h"
- #endif
-
- #ifndef MOVIEFRA_H
- #include "MovieFra.h"
- #endif
-
- #ifndef CMOVIE_H
- #include "CMovie.h"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWPRTITE_H
- #include "FWPrtIte.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPResen.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWMEMMGR_H
- #include "FWMemMgr.h"
- #endif
-
- #ifndef FWFILESP_H
- #include "FWFileSp.h"
- #endif
-
- #ifndef FWSUSINK_H
- #include "FWSUSink.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef _ODSESSM_
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODTranslation_xh
- #include <Translt.xh>
- #endif
-
- // ----- Macintosh Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(__DRAG__)
- #include <Drag.h>
- #endif
-
- //========================================================================================
- // Runtime informations
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfmovie
- #endif
-
- //========================================================================================
- // class CMovieSelection
- //========================================================================================
-
- //---------------------------------------------------------------------------------------
- // CMovieSelection::CMovieSelection
- //---------------------------------------------------------------------------------------
-
- CMovieSelection::CMovieSelection(Environment* ev, CMoviePart* moviePart) :
- FW_CSelection(ev, FALSE, FALSE),
- fMoviePart(moviePart)
- {
- }
-
- //---------------------------------------------------------------------------------------
- // CMovieSelection::~CMovieSelection
- //---------------------------------------------------------------------------------------
-
- CMovieSelection::~CMovieSelection()
- {
- }
-
- //---------------------------------------------------------------------------------------
- // CMovieSelection::CloseSelection
- //---------------------------------------------------------------------------------------
-
- void CMovieSelection::CloseSelection(Environment* ev)
- {
- FW_CPresentationFrameIterator iter(GetPresentation(ev));
- for (CMovieFrame* frame = (CMovieFrame*)iter.First(); iter.IsNotComplete(); frame = (CMovieFrame*)iter.Next())
- frame->CloseSelection(ev);
- }
-
- //---------------------------------------------------------------------------------------
- // CMovieSelection::ClearSelection
- //---------------------------------------------------------------------------------------
-
- FW_Boolean CMovieSelection::ClearSelection(Environment* ev)
- {
- FW_CPresentationFrameIterator iter(GetPresentation(ev));
- for (CMovieFrame* frame = (CMovieFrame*)iter.First(); iter.IsNotComplete(); frame = (CMovieFrame*)iter.Next())
- frame->ClearSelection(ev);
-
- return FALSE;
- }
-
- //---------------------------------------------------------------------------------------
- // CMovieSelection::SelectAll
- //---------------------------------------------------------------------------------------
-
- void CMovieSelection::SelectAll(Environment* ev)
- {
- FW_CPresentationFrameIterator iter(GetPresentation(ev));
- for (CMovieFrame* frame = (CMovieFrame*)iter.First(); iter.IsNotComplete(); frame = (CMovieFrame*)iter.Next())
- frame->SelectAll(ev);
- }
-
- //---------------------------------------------------------------------------------------
- // CMovieSelection::IsEmpty
- //---------------------------------------------------------------------------------------
-
- FW_Boolean CMovieSelection::IsEmpty(Environment* ev) const
- {
- CMovieFrame* activeFrame = (CMovieFrame*)fMoviePart->GetActiveFrame(ev);
- if (activeFrame)
- return activeFrame->IsSelectionEmpty(ev);
- else
- return TRUE;
- }
-
- //---------------------------------------------------------------------------------------
- // CMovieSelection::DoExternalizeSelection
- //---------------------------------------------------------------------------------------
-
- void CMovieSelection::DoExternalizeSelection(Environment* ev,
- ODStorageUnit* destinationSU,
- FW_CCloneInfo* cloneInfo)
- {
- FW_UNUSED(cloneInfo);
-
- CMovieFrame* activeFrame = (CMovieFrame*)fMoviePart->GetActiveFrame(ev);
- FW_ASSERT(activeFrame);
-
- CMovie* theMovie = activeFrame->GetMovie(ev);
-
- if (theMovie)
- {
- FW_PlatformHandle movieHandle;
- ODTranslation *translate = fMoviePart->GetSession(ev)->GetTranslation(ev);
- ODType moovType = translate->GetISOTypeFromPlatformType(ev, 'moov', kODPlatformDataType);
- ODType PICTType = translate->GetISOTypeFromPlatformType(ev, 'PICT', kODPlatformDataType);
-
- {
- FW_CStorageUnitSink sink(destinationSU, kODPropContents, fMoviePart->GetPartKind(ev));
- FW_CWritableStream archive(&sink);
- movieHandle = theMovie->CopyCurrentSelectionToHandle();
- FW_CMemoryManager::LockSystemHandle(movieHandle);
- archive.Write(*movieHandle, FW_CMemoryManager::GetSystemHandleSize(movieHandle));
- FW_CMemoryManager::UnlockSystemHandle(movieHandle);
- FW_CMemoryManager::FreeSystemHandle(movieHandle);
- }
-
- {
- // Add a moov standard type for movies
- // I have to add it because specific to data interchange (not in AddProperties)
- destinationSU->Focus(ev, kODPropContents, kODPosUndefined, NULL,
- (ODValueIndex)0, kODPosUndefined);
- destinationSU->AddValue(ev, moovType);
- FW_CStorageUnitSink sink(destinationSU, kODPropContents, moovType);
- FW_CWritableStream archive(&sink);
- movieHandle = theMovie->CopyCurrentSelectionToHandle();
- FW_CMemoryManager::LockSystemHandle(movieHandle);
- archive.Write(*movieHandle, FW_CMemoryManager::GetSystemHandleSize(movieHandle));
- FW_CMemoryManager::UnlockSystemHandle(movieHandle);
- FW_CMemoryManager::FreeSystemHandle(movieHandle);
- }
-
- {
- // Add a PICT standard type for parts that don't understand movies
- // I have to add it because specific to data interchange (not in AddProperties)
- destinationSU->Focus(ev, kODPropContents, kODPosUndefined, NULL,
- (ODValueIndex)0, kODPosUndefined);
- destinationSU->AddValue(ev, PICTType);
- FW_CStorageUnitSink sink(destinationSU, kODPropContents, PICTType);
- FW_CWritableStream archive(&sink);
- FW_PlatformPict pictHandle = theMovie->GetAsPict();
- FW_CMemoryManager::LockSystemHandle((FW_PlatformHandle)pictHandle);
- archive.Write(*pictHandle, FW_CMemoryManager::GetSystemHandleSize((FW_PlatformHandle)pictHandle));
- FW_CMemoryManager::UnlockSystemHandle((FW_PlatformHandle)pictHandle);
- ::KillPicture(pictHandle);
- }
- }
- }
-
- //---------------------------------------------------------------------------------------
- // CMovieSelection::DoInternalizeSelection
- //---------------------------------------------------------------------------------------
-
- FW_Boolean CMovieSelection::DoInternalizeSelection(Environment* ev,
- ODStorageUnit* sourceSU,
- FW_CCloneInfo* cloneInfo)
- {
- FW_UNUSED(cloneInfo);
-
- FW_Boolean internalized = FALSE;
-
- ODTranslation *translate = fMoviePart->GetSession(ev)->GetTranslation(ev);
- ODType moovType = translate->GetISOTypeFromPlatformType(ev, 'moov', kODPlatformDataType);
- ODType hfsType = translate->GetISOTypeFromPlatformType(ev, 'hfs ', kODPlatformDataType);
- ODType PICTType = translate->GetISOTypeFromPlatformType(ev, 'PICT', kODPlatformDataType);
-
- ODValueType valueType = fMoviePart->GetPartKind(ev);
- FW_Boolean hasMovieHandle = sourceSU->Exists(ev, kODPropContents, valueType, 0);
- if (!hasMovieHandle)
- {
- valueType = moovType;
- hasMovieHandle = sourceSU->Exists(ev, kODPropContents, valueType, 0);
- }
-
- if (hasMovieHandle)
- {
- FW_CStorageUnitSink sink(sourceSU, kODPropContents, valueType);
- FW_CReadableStream archive(&sink);
-
- unsigned long movieSize = sink.GetReadableBytes();
- FW_PlatformHandle movieHandle = FW_CMemoryManager::AllocateSystemHandle(movieSize); // THROW_IF_NULL
- FW_ASSERT(movieHandle != NULL);
-
- FW_CMemoryManager::LockSystemHandle(movieHandle);
- archive.Read(*movieHandle, movieSize);
- FW_CMemoryManager::UnlockSystemHandle(movieHandle);
-
- CMovie* newMovie = CMovie::CreateNewMovieFromHandle(movieHandle);
-
- this->PasteMovie(ev, newMovie);
-
- FW_CMemoryManager::FreeSystemHandle(movieHandle);
-
- internalized = TRUE;
- }
- else if (sourceSU->Exists(ev, kODPropContents, hfsType, 0))
- {
- FW_CStorageUnitSink sink(sourceSU, kODPropContents, hfsType);
- FW_CReadableStream archive(&sink);
-
- unsigned long fileSize = sink.GetReadableBytes();
- HFSFlavor* fileData = (HFSFlavor*)FW_CMemoryManager::AllocateBlock(fileSize);
- archive.Read((char*)fileData, fileSize);
-
- FW_CFileSpecification movieSpec(fileData->fileSpec);
- CMovie* newMovie = CMovie::CreateNewMovieFromFile(movieSpec);
-
- this->PasteMovie(ev, newMovie);
-
- FW_CMemoryManager::FreeBlock(fileData);
- }
- else if (sourceSU->Exists(ev, kODPropContents, PICTType, 0))
- {
- FW_CStorageUnitSink sink(sourceSU, kODPropContents, PICTType);
- FW_CReadableStream archive(&sink);
-
- unsigned long pictSize = sink.GetReadableBytes();
- FW_PlatformPict pictHandle = (FW_PlatformPict)FW_CMemoryManager::AllocateSystemHandle(pictSize);
- FW_ASSERT(pictHandle != NULL);
-
- FW_CMemoryManager::LockSystemHandle((FW_PlatformHandle)pictHandle);
- archive.Read(*pictHandle, pictSize);
- FW_CMemoryManager::UnlockSystemHandle((FW_PlatformHandle)pictHandle);
-
- FW_CPresentationFrameIterator iter(GetPresentation(ev));
- for (CMovieFrame* frame = (CMovieFrame*)iter.First(); iter.IsNotComplete(); frame = (CMovieFrame*)iter.Next())
- frame->PasteHandleToSelection(ev, (FW_PlatformHandle)pictHandle, 'PICT');
-
- ::KillPicture(pictHandle);
-
- internalized = TRUE;
- }
-
- return internalized;
- }
-
- //---------------------------------------------------------------------------------------
- // CMovieSelection::PasteMovie
- //---------------------------------------------------------------------------------------
-
- void CMovieSelection::PasteMovie(Environment* ev, CMovie* newMovie)
- {
- CMovieFrame* activeFrame = (CMovieFrame*)fMoviePart->GetActiveFrame(ev);
- FW_ASSERT(activeFrame);
-
- if (activeFrame->GetMovie(ev))
- {
- FW_CPresentationFrameIterator iter(GetPresentation(ev));
- for (CMovieFrame* frame = (CMovieFrame*)iter.First(); iter.IsNotComplete(); frame = (CMovieFrame*)iter.Next())
- frame->PasteMovieToSelection(ev, newMovie);
-
- delete newMovie;
- }
- else
- {
- FW_CPresentationFrameIterator iter(GetPresentation(ev));
- for (CMovieFrame* frame = (CMovieFrame*)iter.First(); iter.IsNotComplete(); frame = (CMovieFrame*)iter.Next())
- frame->AdoptNewMovie(ev, newMovie);
- }
-
- }
-
-